package com.example.chat.tool;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSONObject;
import com.example.chat.tool.weaher.Weather;
import io.micrometer.common.lang.Nullable;
import org.springframework.ai.tool.annotation.ToolParam;
import org.springframework.stereotype.Component;
import org.springframework.ai.tool.annotation.Tool;

import java.util.HashMap;
import java.util.Map;

/**
 * @author qwert
 * @version 1.0.0
 * @create 2025/8/3 9:52
 **/
@Component
public class WeatherTool implements AITool {
    private final static String BASE_WEATHER_URL = "http://124.222.204.22/api/tianqi/tqyb.php";

    @Override
    public String getName() {
        return null;
    }

    @Tool(description = "查询天气")
    public Weather queryWeather(@ToolParam(description = "省份名称，如：广东省") @Nullable String sheng,
                                @ToolParam(description = "城市/区县名称，如：深圳市") String place) {
        // 这里实现具体的天气查询
        Map<String, Object> param = new HashMap<>();
        param.put("id", "10005885");
        param.put("key", "70c234d9491f832b67804b573a92ea3d");
        param.put("sheng", sheng);
        param.put("place", place);
        return JSONObject.parseObject(HttpUtil.get(BASE_WEATHER_URL, param), Weather.class);
    }

}
